﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using ZLDC.Common.Estate;
namespace ZLDC.Estate.Quantify.Report
{
    public partial class lp_Report_Userlist : System.Web.UI.Page
    {
        public string userid;
        public string statrday = "";
        public string endday = "";
        public string type = "";
        public string deptid = "";
        string depttype;
        public string number;
        protected StringBuilder sb = new StringBuilder();
        protected void Page_Load(object sender, EventArgs e)
        {
            userid = _Request.GetString("userid", _Utility.GetInfoBySession().m_sUserID);
            statrday = _Request.GetString("statrday", DateTime.Now.ToString("yyyy-MM-dd"));
            endday = _Request.GetString("endday", DateTime.Now.ToString("yyyy-MM-dd"));
            deptid = _Request.GetString("deptid", _Utility.GetInfoBySession().m_sDeptID);
            number = _Request.GetString("number", "0");
            depttype = ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(deptid);//获取部门类型
            if (Request.QueryString["type"] != null)
            {
                type = Request.QueryString["type"].ToString();
                btnUpdate.Visible = true;
                divbtn.Style["display"] = "none";
            }
           
            if (!IsPostBack)
            {
                txtTime.Value = statrday;
                GetUserList(statrday, endday, userid);
                GetNum(Convert.ToDateTime(txtTime.Value).AddDays(-1));
            }
        }

        /// <summary>
        /// 查询个人日期总合分
        /// </summary>
        /// <param name="statrday"></param>
        /// <param name="endday"></param>
        /// <param name="userid"></param>
        protected void GetUserList(string statrday, string endday, string userid)
        {
            if (statrday == "0")
            {
                sb.Append(ZLDC.Topo.BLL.Estate.lp_Report_Userlist.GetUserList(statrday, endday, userid, Percentage));
            }
            else
            {
                sb.Append(ZLDC.Topo.BLL.Estate.lp_Report_Userlist.GetUserList(txtTime.Value, txtTime.Value, userid, Percentage));
            }
        }

        /// <summary>
        /// 昨日总分与排名
        /// </summary>
        protected void GetNum(DateTime dt)
        {
            ZLDC.Topo.BLL.Estate.lp_YesterDay.GetNum1(dt, Average, YesterDay, CacheUtility.Cache_GetAllChildDept(deptid), District, deptid, depttype, userid);
            deptqypm.InnerHtml = "今日个人排名：" + ZLDC.Topo.BLL.Estate.lp_Basis.GetQYPM(CacheUtility.Cache_GetAllChildDept(deptid), deptid, Convert.ToDateTime(txtTime.Value),userid);
        }
        
        /// <summary>
        /// 更新个人 量化实际工作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            ZLDC.Topo.BLL.Estate.lp_Report_Userlist.lp_pro_updatelist("1", _Utility.GetInfoBySession().m_sUserID, "", "");
            Response.Write("<script>window.location.href=location.href;</script>");
        }

        protected void btnsel_Click(object sender, EventArgs e)
        {
            
            GetUserList(statrday, endday, userid);
            GetNum(Convert.ToDateTime(txtTime.Value).AddDays(-1));
        }
    }
}
